const logo = new URL('./../../assets/login/app-logo.svg', import.meta.url);
interface State {
    config: {
        isShowGlobalWaterMark: boolean;
        sidebarTitle: string;
        sidebarSubtitle: string;
        sidebarLogo: URL | string;
    };
    common: {
        CommonList: object;
        supplierAreaList: object[];
        loginLoading: boolean;
        curRoute: any; // 左侧导航栏当前的路由
    };
    userInfo: object;
    planId: string | number | null;
}

function getDefaultState(): State {
    return {
        config: {
            isShowGlobalWaterMark: false,
            sidebarTitle: '子系统',
            sidebarSubtitle: '(子标题)',
            sidebarLogo: logo,
        },
        common: {
            CommonList: {},
            // ... 业务系统的 state 写在下方
            supplierAreaList: [],
            loginLoading: false,
            curRoute: '',
        },
        userInfo: {},
    };
}

const state = getDefaultState();

const mutations = {
    // 存下拉列表信息
    onCommonList(state: any, data: any) {
        state.common.CommonList = { ...data };
    },
    // 保存供应商区域列表
    saveSupplierAreaList(state: any, data: any) {
        state.common.supplierAreaList = data;
    },
    setGlobalWaterMark(state: any, isShow: boolean) {
        state.config.isShowGlobalWaterMark = isShow;
    },
    setLoginLoading(state: any, isShow: boolean) {
        state.common.loginLoading = isShow;
    },
    setCurRoute(state: any, route: any) {
        state.common.curRoute = route;
    },

    onUserInfo(state: any, data: any) {
        state.userInfo = { ...data };
    },
};
const actions = {};
const getters = {
    getDicFromCommon: (state: State) => (key: string) => {
        return state.common.CommonList[key];
    },
};

export default {
    namespaced: true,
    state,
    mutations,
    actions,
    getters,
};
